/* $Id$ */
package org.crazydays.gameplan.db.swing;


import javax.swing.JTree;

import org.junit.*;
import static org.junit.Assert.*;

import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;

import org.crazydays.gameplan.db.Database;
import org.crazydays.gameplan.map.IGameMap;

/**
 * DatabaseTreeCellRendererUnitTest
 */
public class DatabaseTreeCellRendererUnitTest
{
    /**
     * Test getTreeCellRendererComponent(...).
     */
    @Test
    public void testGetTreeCellRendererComponent_datbaseNode()
    {
        // objects
        JTree tree = new JTree();
        boolean selected = false;
        boolean expanded = false;
        boolean leaf = false;
        int row = 0;
        boolean hasFocus = false;

        // mocks
        Database database = createMock(Database.class);

        // expect
        expect(database.getName()).andReturn("name");

        // replay
        replay(database);

        // setup
        Object value = new DatabaseNode(database);
        DatabaseTreeCellRenderer renderer = new DatabaseTreeCellRenderer();

        // test
        renderer.getTreeCellRendererComponent(tree, value, selected, expanded,
            leaf, row, hasFocus);

        // verify
        verify(database);

        assertNotNull("closedIcon", renderer.getClosedIcon());
        assertNotNull("leafIcon", renderer.getLeafIcon());
        assertNotNull("openIcon", renderer.getOpenIcon());
        assertEquals("equals1", renderer.getClosedIcon(), renderer
            .getLeafIcon());
        assertEquals("equals2", renderer.getClosedIcon(), renderer
            .getOpenIcon());
    }

    /**
     * Test getTreeCellRendererComponent(...).
     */
    @Test
    public void testGetTreeCellRendererComponent_mapsNode()
    {
        // objects
        JTree tree = new JTree();
        boolean selected = false;
        boolean expanded = false;
        boolean leaf = false;
        int row = 0;
        boolean hasFocus = false;

        // setup
        Object value = new MapsNode();
        DatabaseTreeCellRenderer renderer = new DatabaseTreeCellRenderer();

        // test
        renderer.getTreeCellRendererComponent(tree, value, selected, expanded,
            leaf, row, hasFocus);

        // verify
        assertNotNull("closedIcon", renderer.getClosedIcon());
        assertNotNull("leafIcon", renderer.getLeafIcon());
        assertNotNull("openIcon", renderer.getOpenIcon());
        assertEquals("equals1", renderer.getClosedIcon(), renderer
            .getLeafIcon());
        assertEquals("equals2", renderer.getClosedIcon(), renderer
            .getOpenIcon());
    }

    /**
     * Test getTreeCellRendererComponent(...).
     */
    @Test
    public void testGetTreeCellRendererComponent_mapNode()
    {
        // objects
        JTree tree = new JTree();
        boolean selected = false;
        boolean expanded = false;
        boolean leaf = false;
        int row = 0;
        boolean hasFocus = false;

        // mocks
        IGameMap gameMap = createMock(IGameMap.class);

        // expect
        expect(gameMap.getName()).andReturn("name");

        // replay
        replay(gameMap);

        // setup
        Object value = new MapNode(gameMap);
        DatabaseTreeCellRenderer renderer = new DatabaseTreeCellRenderer();

        // test
        renderer.getTreeCellRendererComponent(tree, value, selected, expanded,
            leaf, row, hasFocus);

        // verify
        verify(gameMap);

        assertNull("closedIcon", renderer.getClosedIcon());
        assertNull("leafIcon", renderer.getLeafIcon());
        assertNull("openIcon", renderer.getOpenIcon());
    }
}
